(function ($) {
    $.fn.magicline = function (options) {
        var settings = {
            mc:this,
            mch:"<li class='on'></li>",
            list:"#nav-list>li"
        };
        if (options) {
            $.extend(settings, options);
        }
        var $el, leftPos, newWidth;
        $(this).append(settings.mch);
        /* Cache it */
        var $magicLine = $(settings.mc);

        $magicLine
            .width($("li.on").width())
            .css("left", $("li.on").position().left)
            .data("origLeft", $magicLine.position().left)
            .data("origWidth", $magicLine.width());

        $(settings.list).find("a").hover(function() {
            $el = $(this);
            leftPos = $el.position().left;
            newWidth = $el.parent().width();

            $magicLine.stop().animate({
                left: leftPos,
                width: newWidth
            });
        }, function() {
            $magicLine.stop().animate({
                left: $magicLine.data("origLeft"),
                width: $magicLine.data("origWidth")
            });
        });
    }
})(jQuery);